package com.assessment.servermanager.controller;

import javax.servlet.http.HttpServletResponse;

import com.assessment.servermanager.commen.controller.BaseController;
import com.assessment.servermanager.commen.entity.AjaxResult;
import com.assessment.servermanager.commen.entity.PageQuery;
import com.assessment.servermanager.commen.page.TableDataInfo;
import com.assessment.servermanager.commen.utils.BeanCopyUtils;
import com.assessment.servermanager.commen.utils.bean.BeanUtils;
import com.assessment.servermanager.entity.TbPaper;
import com.assessment.servermanager.entity.bo.TbPaperBo;
import com.assessment.servermanager.entity.vo.TbPaperVo;
import com.assessment.servermanager.service.ITbPaperService;
import javafx.scene.control.Tab;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 【试卷】Controller
 *
 * @author jiajia
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/paper")
public class TbPaperController extends BaseController {
    @Autowired
    private ITbPaperService tbPaperService;

    /**
     * 查询【试卷】列表
     */
    @GetMapping("/list")
    public TableDataInfo<TbPaperVo> list(TbPaperBo tbPaperBo, PageQuery pageQuery) {
        return tbPaperService.selectTbPaperList(tbPaperBo,pageQuery);
    }

    /**
     * 导出【试卷】列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPaper tbPaper) {
       /* List<TbPaper> list = tbPaperService.selectTbPaperList(tbPaper);
        ExcelUtil<TbPaper> util = new ExcelUtil<TbPaper>(TbPaper.class);
        util.exportExcel(response, list, "【试卷】数据");*/
    }

    /**
     * 获取【试卷】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbPaperService.selectTbPaperById(id));
    }

    /**
     * 新增【试卷】
     */
    @PostMapping
    public AjaxResult add(@RequestBody TbPaperBo tbPaper) {
        return toAjax(tbPaperService.insertTbPaper(tbPaper));
    }

    /**
     * 修改【试卷】
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TbPaper tbPaper) {
        return toAjax(tbPaperService.updateTbPaper(tbPaper));
    }

    /**
     * 删除【试卷】
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbPaperService.deleteTbPaperByIds(ids));
    }

    /**
     * 生成或者发布试卷
     *
     * 前端给你传个类型   类型1就是生成试题  类型2就是发布试卷
     *
     * @param id 试题id
     * @param type 类型 是要生成试题，还是要发布    1生成 2发布
     * @return AjaxResult
     */
    @GetMapping("/generterQuestion")
    public AjaxResult generterQuestionOrPublish(@RequestParam Long id,@RequestParam Integer type){
        return toAjax(tbPaperService.generterQuestionOrPublish(id,type));
    }

    /**
     * 获取试卷的题目
     * @param paperId 试卷id
     */
    @GetMapping("/getQuestionByPaperId/{paperId}")
    public AjaxResult getQuestionByPaperId(@PathVariable Long paperId){
        return AjaxResult.success(tbPaperService.getQuestion(paperId));
    }
}
